package com.example;



import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;

@Configuration
@EnableWebSocketMessageBroker
public class webSocketConfig extends AbstractWebSocketMessageBrokerConfigurer{

	@Override
	public void registerStompEndpoints(StompEndpointRegistry registry) {
		registry.addEndpoint("/endpointWisely").withSockJS();
	}
	
	@Override
	public void configureMessageBroker(MessageBrokerRegistry registry){
		registry.enableSimpleBroker("/topic/getResponse");
	}

}
/**代码解释
 * 1。通过@EnableWebSocketMessageBroker注解开启使用STOMP协议来传输
 * 基于代理的消息。这时控制器支持使用@MessageMapping就像使用@RequestMapping
 * 2。注册STOMP协议的节点，并映射的指定的URL
 * 3。注册一个STOMP的endpoint,并指定使用SockJS协议
 * 4。配置消息代理（MessageBroker）
 * 5。广播式应配置一个/topic消息代理
 */